package com.vancouver.knows.business.tracker;

import android.os.Message;

import java.util.ArrayList;
import java.util.List;

import com.pangu.task.IResultReceiver;
import com.pangu.task.OperateResult;
import com.vancouver.knows.business.BusinessModule;
import com.vancouver.knows.business.Constants;
import com.vancouver.knows.business.bean.CommentInfo;
import com.vancouver.knows.business.task.mark.UserInsertCommentTaskMark;

/**
 * 发布评论
 * <p/>
 * Created by cxlin
 */
public class UserInsertCommentTracker extends ABInvokeTracker {

	public UserInsertCommentTracker(BusinessModule module, IResultReceiver resultReceiver) {
		super(module, resultReceiver);
	}

	@Override
	public String TAG() {
		return UserInsertCommentTracker.class.getSimpleName();
	}

	@Override
	public void handleResult(OperateResult result) {
		CommentInfo commentInfo = (CommentInfo) result.getResultData();
		if (commentInfo == null)
			return;

		UserInsertCommentTaskMark aTaskMark = (UserInsertCommentTaskMark) result.getTaskMark();
		List<CommentInfo> commentInfoList = module.getCacheManager().getCommentInfoMap().get(aTaskMark.getPostId());
		if (commentInfoList == null) {
			commentInfoList = new ArrayList<CommentInfo>();
			module.getCacheManager().getCommentInfoMap().put(aTaskMark.getPostId(), commentInfoList);
		}

		commentInfoList.add(0, commentInfo);

		Message msg = Message.obtain();
		msg.what = Constants.BUSINESS_STATUS_INSERT_COMMENT;
		msg.obj = commentInfo.getPostId();
		imContext.handleMobMessage(msg);
	}
}
